<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ page import="net.sapfree.core.db.RecordSet"%>
<%@ page import="net.sapfree.core.db.Record"%>
<%@ page import="net.sapfree.core.db.PagingInfo"%>
<%@ page import="java.util.HashMap"%>
<%@ page import="java.util.Map"%>
<%@ page import="net.sapfree.article.ArticleHandler"%>

<%@ taglib uri="/WEB-INF/sapfree-info.tld" prefix="sap" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

//显示博客主人的信息
String bloguuid=(String)request.getAttribute("bloguuid");
String personuuid = "";

/*
if(personuuid.equals("")){
   personuuid="c7fc6f5b-4f4c-4238-992c-e7acb6f908fb";
}
*/

RecordSet nearRecordSet = (RecordSet) request.getAttribute("nearRecordSet");
String preUuid = "";
String preName = "";
String lastUuid = "";
String lastName = "";
for(int i=0;i<nearRecordSet.size();i++){
	Record record = nearRecordSet.get(i);
	personuuid=record.getString("AI_PERSONUUID");
	if(record.getString("SEQUENCE","").equals("PRE")){
		preUuid = record.getString("AI_UUID");
		preName = record.getString("AI_TITLE");
	}else if(record.getString("SEQUENCE","").equals("LAST")){
		lastUuid = record.getString("AI_UUID");
		lastName = record.getString("AI_TITLE");
	}
	System.out.println("sssss");
}
System.out.println("personuuid from jsp is "+personuuid);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="login,regist first">
<meta http-equiv="description" content="This is login page">

<title>我的飞客</title>
<link href="<%=path%>/include/styleBase/css/ostable.css" rel="stylesheet"></link>
<link href="<%=path%>/include/styleBase/css/leftPage.css" rel="stylesheet"></link>
<link href="<%=path%>/include/styleBase/css/tagStyle.css" rel="stylesheet"></link>
<link href="<%=path%>/include/styleBase/css/fontStyle.css" rel="stylesheet"></link>

<link href="<%=path%>/include/styleBase/css/headfoot.css" rel="stylesheet"></link>

<script type="text/javascript" src="<%=path%>/include/KindEditor/kindeditor.js"></script>
<script type="text/javascript" src="<%=path%>/include/js/jquery.js"></script>

<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style>
<script>


function saveBlog(){
	content = KE.util.getPureData("editorContent")
	//htmlcontent = KE.html("editorContent");
	$("#CONTENT").val(content);
	document.frm.action="<%=path%>/article/articlelist?method=saveNewBlog";
	document.frm.submit();
}

function newBlog(){
	window.open('<%=path%>/article/articlelist?method=newBlog')
}

function blogDetail(bloguuid){
	document.frm.action="<%=path%>/article/articlelist?method=blogDetail&bloguuid="+bloguuid;
	document.frm.submit();
}

function senddisc(){
	var bloguuid = $("#AD_AD_ARTICLEUUID").val();
	var content = $("#AD_AD_CONTENT").val();
	$.ajax({
		 	type:"POST",
		 	url:"<%=path%>/article/articlelist?method=saveDisc&AD_AD_ARTICLEUUID="+bloguuid,
		 	data:{AD_AD_CONTENT:content},
		 	error:function(){
				alert("与服务器失去联系，请刷新本页面后再重试！");
				return;
			},
		 	success:function(msg){
		 		setDiv();//重新刷新评论列表
		 		setArtCount();//重写本页面文章的评论数、阅读数、UP数
		 		$("#AD_AD_CONTENT").val("");
		 		
		 	}
	})
}


function deleteDisc(ad_uuid,ai_uuid){
	$.ajax({
		 	type:"POST",
		 	url:"<%=path%>/article/articlelist?method=deleteDisc&ad_uuid="+ad_uuid+"&ai_uuid="+ai_uuid,
		 	error:function(){
				alert("与服务器失去联系，请刷新本页面后再重试！");
				return;
			},
		 	success:function(msg){
		 		alert('删除成功');
		 		setDiv();//重新刷新评论列表
		 		setArtCount();//重写本页面文章的评论数、阅读数、UP数
		 		
		 	}
	})
}


function addReadCount(){ 
	$.ajax({
		 	type:"POST",
		 	url:"<%=path%>/article/articlelist?method=addReadCount&bloguuid=<%=bloguuid%>",
		 	error:function(){
				alert("与服务器失去联系，请刷新本页面后再重试！");
				return;
			},
		 	success:function(msg){
		 	}
	})
}

//动态写评论列表div
function setDiv(){
	$("#DiscussWait").show();
	$("#discDiv").html("");
	$.ajax({
		 	type:"POST",
		 	url:"<%=path%>/article/articlelist?method=getDiscListByBlogId&bloguuid=<%=bloguuid%>",
		 	error:function(){
				alert("与服务器失去联系，请刷新本页面后再重试！");
				return;
			},
		 	success:function(msg){
		 		var user = eval(msg);
		 		for(var i=0;i<user.length;i++){
		 			
			        var str="<div style=\"border-bottom:1px dashed;margin-top:20px;\">";
			        str=str+"<div style=\"width:100%\">";
				    str=str+"<span style=\"float:left;\"><a href=\"#2011\" style=\"margin-left:30px;\">"+user[i].ad_personname+"</a></span>";
				    str=str+"<span style=\"float:right;margin-left:10px;margin-right:100px;\"><a href=\"#2011\" onclick=\"deleteDisc(\'"+user[i].ad_uuid+"\',\'"+user[i].ad_articleuuid+"\')\">[删除]</a></span>";
				    str=str+"<span style=\"float:right;\">"+user[i].ad_publishtime+"</span>";
			        str=str+"</div>";
			        str=str+"<div style=\"margin-top:20px;margin-bottom:10px;margin-left:30px;\">";
			        str=str+user[i].ad_content;
			       	str=str+"</div>";
			        str=str+"</div>";
		 			
		 			$("#discDiv").append(str);
		 		}
		 		
		 		//把 加载中 的图片去掉
		 		$("#DiscussWait").hide();
		 	}
	})
}



//动态写评论数、阅读数、UP数
function setArtCount(){
	$.ajax({
		 	type:"POST",
		 	url:"<%=path%>/article/articlelist?method=getArticleByUuid&bloguuid=<%=bloguuid%>",
		 	error:function(){
				alert("与服务器失去联系，请刷新本页面后再重试！");
				return;
			},
		 	success:function(msg){
		 		var article = eval(msg);
		 		$("#dCountSpan").html(article[0].ai_discusscount);
		 		$("#rCountSpan").html(article[0].ai_readcount);
		 		$("#upCountSpan").html(article[0].ai_upcount);
		 	}
	})
}

function seaBlogByTag(tagid){
	alert(tagid);
}

$(document).ready(function(){
	addReadCount();//刷新文章阅读数
	setDiv();
});

function blogDetail(bloguuid){
	document.frm.action="<%=path%>/article/articlelist?method=blogDetail&bloguuid="+bloguuid;
	document.frm.submit();
}
</script>

</head>
<body>
<form name="frm" method="post">

<input style="" type="hidden" id="AD_AD_ARTICLEUUID" name="AD_AD_ARTICLEUUID" value="<%=bloguuid%>"/>


<!--#include file="top.htm"-->
<%@include file="../../include/jsp/top.jsp"%>

<sap:Article artId="<%=bloguuid%>">

<table border="0" cellpadding="0" cellspacing="0" width="1000" align="center">
	<tr>
    	
    	<td width="190" valign="top">
        <!--左侧功能导航区-->
        <%@include file="../../include/jsp/leftpersonphoto.jsp"%> 
       	<%@include file="../../include/jsp/leftpersoninfo.jsp"%> 
        <!--左侧功能导航区-->
        </td>
        <td width="10"></td>
      <td width="780" valign="top">
        <!--中间主信息展示区-->
         
        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" width="98%" align="center">
        	<!--<tr>
           	  <td colspan="2" class="blueBold14" height="30">
			  	<img src="../images/report_edit.png" border="0">&nbsp;正文
				&nbsp;&nbsp;
			  </td>
            </tr>
        	<tr><td height="5"> <hr width="100%" size="1" color="#999999"></td></tr>
        	-->
            <tr>
            	<td colspan="2">
            	 
            	
	            	 <table border="0" cellpadding="0" cellspacing="0" width="99%">
		            	<tr>
		                	<td class="lightBlueBold14" colspan="2" height="30">
		                		<sap:write property="AI_TITLE"/>&nbsp;&nbsp;
								<span class="greyNormal12"><sap:write property="AI_PUBLISHTIME"/></span>
							</td>
		                </tr>
		            	<tr>
		                	<td class="blackNormal12" height="25" colspan="2">
							标签：
								<%
					      	 	 String articleId=(String)pageContext.getAttribute("articleId");
					      	 	 RecordSet tagRst = ArticleHandler.getTagInfoByArtId(articleId);
					      	 	 for(int j=0;j<tagRst.size();j++){
					      	 	 	Record tagrecord = tagRst.get(j);
					      	 	 %>
					      	 	 	<a href="#2011" onClick="seaBlogByTag('<%=tagrecord.getString("AT_TAGUUID","")%>');"><%=tagrecord.getString("AT_TAGNAME","")%></a>
					      	 	<%}%>
							</td>
		                </tr>
		                <tr>
		                	<td height="100%" colspan="2">
		                	<sap:write property="AC_HTML_CONTENT"/>
							</td>
		                </tr>
		            </table>
	           
	           
	           
	            <div>
	            	  <sap:VoteList articleId="<%=articleId%>">
				          <sap:Vote>
								      <table border="0" cellpadding="0" cellspacing="1" width="98%" bgcolor="#666666">
								      <tr>
								      	<td align="center" bgcolor="#FFFFFF">
								      	
								      	<table border="0" cellpadding="0" cellspacing="0" width="98%">
				            	<tr>
				                	<td height="30" colspan="2" class="blackBold14"><img src="../images/chart_bar_edit.png">&nbsp;<sap:write property="VI_TITLE"/>  </td>
				                </tr>
				                <tr><td height="25" colspan="2" class="greyNormal12">
				                		<!--发起时间：<sap:write property="VI_STARTDATE"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-->
				                		截止时间：<sap:write property="VI_CLOSEDATE"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				                		投票人数：<sap:write property="RCOUNT"/>人</td></tr>
				                <tr><td height="5" colspan="2"></td></tr>
				               
						           <%
							      	  String voteId=(String)pageContext.getAttribute("voteId");
									  String isclosed = (String)pageContext.getAttribute("isclosed");
							      	%>
								    <jsp:include   page="/quan/vote.jsp"    flush="true">   
										<jsp:param name="voteId" value="<%=voteId %>" />
                                        <jsp:param name="isclosed" value="<%=isclosed%>" />
									</jsp:include>
												
				                        
				                        <tr><td height="10"></td></tr>
				                    </table>                   
				                    
				                     </td>
				                </tr>
				          
				            </table>
					      
				  		</sap:Vote>
				     </sap:VoteList>  
	            </div>
	            
	            <div style="margin-top:20px;" class="greyNormal12">
	            	阅读（<span id="rCountSpan"><sap:write property="AI_READCOUNT"/></span>）&nbsp;&nbsp;|&nbsp;&nbsp;评论（<span id="dCountSpan"><sap:write property="AI_DISCUSSCOUNT"/></span>）&nbsp;&nbsp;|&nbsp;&nbsp;收藏（<span id="upCountSpan"><sap:write property="AI_UPCOUNT"/></span>）
	            </div>
            	</td>
            </tr>
        	<tr><td align="center" height="20" colspan="2"><div style="border-top:1px dashed #cccccc;height: 1px;overflow:hidden; width:100%;"></div></td></tr>
           
           <%if(!preUuid.equals("")){%>
            <tr>
            	<td height="25" class="blackNormal14" align="left">
					前一篇：<a href="#2011" style="text-decoration:none" onClick="blogDetail('<%=preUuid%>')"><%=preName%></a>
				</td>
                <td height="25" class="blackNormal14" align="right">
                </td>
            </tr>
            <%}%>
            
            
            <%if(!lastUuid.equals("")){%>
				<tr>
            	<td height="25" class="blackNormal14" align="left">
					后一篇：<a href="#2011" style="text-decoration:none" onClick="blogDetail('<%=lastUuid%>')"><%=lastName%></a>
				</td>
                <td height="25" class="blackNormal14" align="right">
                </td>
            </tr>
			<%}%>
            
            
        </table>
         
        <div style="background-color:#EBF6FC;border:1px solid #C4CDE0;margin-top:20px;">
        	<div style="margin:2px;" >评论</div>
        </div>
        
        
        <div id="DiscussWait" style="text-align:center;"> 
			<img src="<%=path%>/include/images/loading.gif" />加载中……
		</div>
        
        <div id="discDiv" class="greyNormal12">
        	<div style="border-bottom:1px dashed;margin-top:20px;">
        		<div style="width:100%">
	        		<span style="float:left;"><a href="#2011">周义</a></span>
	        		<span style="float:right;margin-left:10px;margin-right:20px;"><a href="#2011r">[删除]</a></span>
	        		<span style="float:right;">2011-08-11 11:52:23</span>
        		</div>
        		<div style="margin-top:20px;margin-bottom:10px;">
        			asdfdsfsadfasdf
        		</div>
        	</div>
        </div>
        
        <div style="brder-bottom:1px;margin-top:20px;">
        	<textarea class=""  id ="AD_AD_CONTENT" name="AD_AD_CONTENT" minlength="20"  label="发表评论" style="width:98%;height:100px;"></textarea>
        </div>
        
        <input id="Button3" class="bigBtn" style="" type="button" value="发评论" onClick="senddisc()" />&nbsp;&nbsp;
       
       
      <!--中间主信息展示区-->
      </td>
      <td width="10"></td>
        
	</tr>
</table>

</sap:Article>
<br>
<table border="0" cellpadding="0" cellspacing="0" width="1000" align="center">
	<tr><td height="10"></td></tr>
	<tr><td><hr color="#999999" size="1" width="100%"></td></tr>
	<tr>
    	<td align="center" height="25">
        （C） 2011-2016 Sapfree.com
        </td>
    </tr>
    <tr>
    	<td align="center" height="25">
        联系我们&nbsp;&nbsp;隐私声明&nbsp;&nbsp;使用条款&nbsp;&nbsp;版权商标&nbsp;&nbsp;网站地图
        </td>
    </tr>
</table>
<br><br>
   


</form>
</body>
</html>